﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RobotsSample
{

    public class Sample_CarRobot : RobotSampleAbstract
    {
        /// <summary>
        /// 轮子组成的模式
        /// 模式
        /// 2：两轮
        /// 3：三轮
        /// 4：四向轮
        /// 5：四麦轮
        /// 6：四并轮
        /// </summary>
        private int _mode;

        /// <summary>
        /// 2：两轮
        /// 3：三轮
        /// 4：四向轮
        /// 5：四麦轮
        /// 6：四并轮
        /// </summary>
        /// <param name="mode"></param>
        public Sample_CarRobot(int mode)
        {
            _mode = mode;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="defaultIds">T:L1,T:L1,T:L3,T:L3,T:R1,T:R1,T:R3,T:R3</param>
        /// <returns></returns>
        public override bool Run(string ip, int port, byte[] defaultIds = null)
        {
            var isSuccess = ConnectRobot(ip, port);
            if (!isSuccess)
            {
                return false;
            }
            ScanModulesIds(defaultIds);

            if (!isSuccess)
            {
                return false;
            }

            var ids = ModulesIds.Select(p => (byte)p).ToArray();

            RobotId = MiniBotAlgorithmLib.AddRobot((int)RobotTypeEnum.Car, ids, _mode);
            var rs = MiniBotAlgorithmLib.BindRobotModuleApis(RobotId, SetPositionCallback, SetPositionWithSpeedCallback, SetMultiPositionCallback,
                    SetMultiPositionWithSpeedCallback, SetSpeedCallback, SetRunningSpeedCallback, SetTorqueEnableCallback, SetModeCallback);

            return rs;
        }
    }
}
